using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
namespace RefCheckRewrite {
	public partial class frmMain:Form {
		FileInfo _file;
		public frmMain(FileInfo file) {
			_file=file;

			InitializeComponent();
			this.DragEnter+=Form1_DragEnter;
			this.DragDrop+=Form1_DragDrop;
			if(file!=null)
			{
				new RefCheck(_file).Validate(treeView1);
				Text=_file.Name;
			}
			else
				treeView1.Nodes.Add("<drag and drop any .NET dll or exe>");
		}
		private void Form1_DragEnter(object sender,DragEventArgs e) {
			e.Effect=e.Data.GetDataPresent(DataFormats.FileDrop)?DragDropEffects.Link:DragDropEffects.None;
		}
		private void Form1_DragDrop(object sender,DragEventArgs e) {
			if(e.Data.GetDataPresent(DataFormats.FileDrop))
			{
				string[] filePaths=(e.Data.GetData(DataFormats.FileDrop) as string[]);
				if(1==filePaths.Length)
				{
					_file=new FileInfo(filePaths[0]);
					new RefCheck(_file).Validate(treeView1);
					Text=_file.Name;
				}
			}
		}
		private void treeView1_KeyUp(object sender,KeyEventArgs e) {
		}
		private void treeView1_KeyDown(object sender,KeyEventArgs e) {
			if(e.KeyCode==Keys.F5)
			{
				new RefCheck(_file).Validate(treeView1);
				Text=_file.Name;
			}
			else if(e.KeyCode==Keys.Escape)
			{
				Application.Exit();
			}
			else if(e.Alt||e.Control)
			{
				if(e.KeyCode==Keys.O&&File.Exists(treeView1.SelectedNode.ToolTipText))
				{
					FileInfo fi=new FileInfo(treeView1.SelectedNode.ToolTipText);
					System.Diagnostics.Process.Start(fi.DirectoryName);
					//System.Diagnostics.Process.Start("explorer.exe",@"/select,"+fi);
				}
				else if(e.KeyCode==Keys.S)
				{
					string filename=string.Format("{0}{1:yyMMddHHmmss}.png",_file.Name,DateTime.Now);
					Bitmap bmp=new Bitmap(treeView1.ClientRectangle.Width,treeView1.ClientRectangle.Height);
					treeView1.DrawToBitmap(bmp,treeView1.ClientRectangle);
					bmp.Save(filename,System.Drawing.Imaging.ImageFormat.Png);
					System.Diagnostics.Process.Start(filename);
				}
				else if(e.KeyCode==Keys.D)
				{
					using(FrmFileTime form=new FrmFileTime(_file))
						form.ShowDialog();


				}
			}
		}
	}
}